﻿using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using OpenAdmin.Core.DbContextLocators;

namespace OpenAdmin.Core.Models;

/// <summary>
/// 产品表
/// </summary>
[Table("Products")]
public class Product : EntityBase<MallDbContextLocator>, IEntityTypeConfigure<Product>, IEntityTypeSeedDataConfigure<Product>
{
    /// <summary>
    /// 产品名称
    /// </summary>
    public string Name { get; set; }

    /// <summary>
    /// 产品原价格
    /// </summary>
    public decimal Price { get; set; }

    /// <summary>
    /// 是否促销
    /// </summary>
    public bool IsSale { get; set; }

    /// <summary>
    /// 产品促销价格
    /// </summary>
    public decimal SalePrice { get; set; }

    /// <summary>
    /// 产品描述
    /// </summary>
    public string Description { get; set; }

    /// <summary>
    /// 封面图片
    /// </summary>
    public string Cover { get; set; }

    /// <summary>
    /// 跳转地址
    /// </summary>
    public string Link { get; set; }

    /// <summary>
    /// 是否热卖
    /// </summary>
    public bool IsHot { get; set; }

    /// <summary>
    /// 是否上架
    /// </summary>
    public bool IsOn { get; set; }

    /// <summary>
    /// 是否推荐
    /// </summary>
    public bool IsRecommend { get; set; }

    /// <summary>
    /// 排序
    /// </summary>
    public int Sort { get; set; }

    public void Configure(EntityTypeBuilder<Product> entityBuilder)
    {
        entityBuilder.Property(p => p.Name).HasMaxLength(64);
        entityBuilder.Property(p => p.Price).HasColumnType("decimal(11,2)");
        entityBuilder.Property(p => p.SalePrice).HasColumnType("decimal(11,2)");
        entityBuilder.Property(p => p.Description).HasMaxLength(256);
        entityBuilder.Property(p => p.Cover).HasMaxLength(128);
        entityBuilder.Property(p => p.Link).HasMaxLength(128);
    }

    public IEnumerable<Product> HasData(DbContext dbContext)
    {
        return new List<Product>
        {
            new Product { Id = 1, Name = "产品名称一", Price = 12.78m, IsSale = false, SalePrice = 12, Description = "产品名称描述一", IsHot = false, IsOn = false, IsRecommend = false, Cover = "https://s10.mogucdn.com/mlcdn/c45406/180926_45fkj8ifdj4l824l42dgf9hd0h495_750x390.jpg", Link = "https://act.mogujie.com/huanxin0001?acm=3.mce.2_10_1jhwa.43542.0.ccy5br4OlfK0Q.pos_0-m_454801-sd_119", Sort = 1, CreateTime = DateTime.Now },
            new Product { Id = 2, Name = "产品名称二", Price = 54.4m, IsSale = false, SalePrice = 52.39m, Description = "产品名称描述二", IsHot = false, IsOn = false, IsRecommend = false, Cover = "https://s10.mogucdn.com/mlcdn/c45406/180926_31eb9h75jc217k7iej24i2dd0jba3_750x390.jpg", Link = "https://act.mogujie.com/ruqiu00001?acm=3.mce.2_10_1ji16.43542.0.ccy5br4OlfK0R.pos_1-m_454889-sd_119", Sort = 2, CreateTime = DateTime.Now },
            new Product { Id = 3, Name = "产品名称三", Price = 67.3m, IsSale = false, SalePrice = 66.99m, Description = "产品名称描述三", IsHot = false, IsOn = false, IsRecommend = false, Cover = "https://s10.mogucdn.com/mlcdn/c45406/180919_3f62ijgkj656k2lj03dh0di4iflea_750x390.jpg", Link = "https://act.mogujie.com/huanji001?acm=3.mce.2_10_1jfj8.43542.0.ccy5br4OlfK0S.pos_2-m_453270-sd_119", Sort = 3, CreateTime = DateTime.Now },
            new Product { Id = 4, Name = "产品名称四", Price = 25.9m, IsSale = false, SalePrice = 22.3m, Description = "产品名称描述四", IsHot = false, IsOn = false, IsRecommend = false, Cover = "https://s10.mogucdn.com/mlcdn/c45406/180917_18l981g6clk33fbl3833ja357aaa0_750x390.jpg", Link = "https://act.mogujie.com/liuxing00001?acm=3.mce.2_10_1jepe.43542.0.ccy5br4OlfK0T.pos_3-m_452733-sd_119", Sort = 4, CreateTime = DateTime.Now },
            new Product { Id = 5, Name = "产品名称五", Price = 35.63m, IsSale = false, SalePrice = 32, Description = "产品名称描述五", IsHot = false, IsOn = false, IsRecommend = false, Cover = "https://s10.mogucdn.com/mlcdn/c45406/180913_036dli57aah85cb82l1jj722g887g_225x225.png", Link = "http://act.meilishuo.com/10dianlingquan?acm=3.mce.2_10_1dggc.13730.0.ccy5br4OlfK0U.pos_0-m_313898-sd_119", Sort = 5, CreateTime = DateTime.Now },
            new Product { Id = 6, Name = "产品名称六", Price = 63.29m, IsSale = false, SalePrice = 60.99m, Description = "产品名称描述六", IsHot = false, IsOn = false, IsRecommend = false, Cover = "https://s10.mogucdn.com/mlcdn/c45406/180913_25e804lk773hdk695c60cai492111_225x225.png", Link = "https://act.mogujie.com/tejiazhuanmai09?acm=3.mce.2_10_1dgge.13730.0.ccy5br4OlfK0V.pos_1-m_313899-sd_119", Sort = 6, CreateTime = DateTime.Now },
            new Product { Id = 7, Name = "产品名称七", Price = 51.54m, IsSale = false, SalePrice = 50.99m, Description = "产品名称描述七", IsHot = false, IsOn = false, IsRecommend = false, Cover = "https://s10.mogucdn.com/mlcdn/c45406/180913_387kgl3j21ff29lh04181iek48a6h_225x225.png", Link = "http://act.meilishuo.com/neigouful001?acm=3.mce.2_10_1b610.13730.0.ccy5br4OlfK0W.pos_2-m_260486-sd_119", Sort = 7, CreateTime = DateTime.Now },
            new Product { Id = 8, Name = "产品名称八", Price = 38.88m, IsSale = false, SalePrice = 36.9m, Description = "产品名称描述八", IsHot = false, IsOn = false, IsRecommend = false, Cover = "https://s10.mogucdn.com/mlcdn/c45406/180913_8d4e5adi8llg7c47lgh2291akiec7_225x225.png", Link = "http://act.meilishuo.com/wap/yxzc1?acm=3.mce.2_10_1dggg.13730.0.ccy5br4OlfK0X.pos_3-m_313900-sd_119", Sort = 8, CreateTime = DateTime.Now },
        };
    }
}
